package controller

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"github.com/e421083458/gin_scaffold/dao"
	"github.com/e421083458/gin_scaffold/dto"
	"github.com/e421083458/gin_scaffold/middleware"
	jwt "github.com/e421083458/gin_scaffold/public"
	"github.com/e421083458/golang_common/lib"
	"github.com/gin-gonic/gin"
	"github.com/shopspring/decimal"
	"github.com/signintech/gopdf"
	"github.com/spf13/viper"
	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/core/option"
	"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
	"github.com/wechatpay-apiv3/wechatpay-go/utils"
	"io/ioutil"
	"log"
	"net/http"
	"path"
	"strconv"
)

type ApiController struct {
}
type RespWXSmall struct {
	Openid     string `json:"openid"`      //用户唯一标识
	Sessionkey string `json:"session_key"` //会话**
	Unionid    string `json:"unionid"`     //用户在开放平台的唯一标识符，在满足 UnionID 下发条件的情况下会返回，详见 UnionID 机制说明。
	Errcode    int    `json:"errcode"`     //错误码
	ErrMsg     string `json:"errMsg"`      //错误信息
	Uid        int    `json:"uid"`
	Token      string `json:"token"` //jwt token
	Headimgurl string `json:"headimgurl"`
}

// ApiRegister 不要求登录的接口 公共接口
func ApiRegister(router *gin.RouterGroup) {
	curd := ApiController{}

	router.GET("/pdftest", curd.TestTable)              //pdf 绘制 -> oss 存储
	router.GET("/wx/login", curd.Login)                 //微信授权登录  JWT
	router.GET("/wx/news", curd.News)                   //健康贴士
	router.GET("/wx/find_news", curd.NewsID)            //健康贴士详情
	router.GET("/wx/find_news_list", curd.NewsList)     //健康贴士4分类
	router.GET("/wx/find_move_list", curd.MoveNewsList) //专家

	router.OPTIONS("/upload", curd.UploadFile) //公共上传类/富文本编辑器图片上传
	router.GET("/wx/notice", curd.Notice)      //获取公告
	router.GET("/ddj/tb", curd.Tongbu)         //大数据同步
	//商城 和 发现 todo
	router.GET("/user/qrcode", curd.Qrcode)
	router.GET("/qrcode", curd.Dlqrcode) //小程序二维码代理商
	router.GET("/qrcode2", curd.qrcode2) //小程序二维码代理商2
	router.GET("/scheme", curd.Scheme)   //小程序url scheme 实现跳转到小程序页面

}

// ApiLoginRegister 要求登录的接口
func ApiLoginRegister(router *gin.RouterGroup) {
	curd := ApiController{}
	//router.POST("/user/test", curd.Test)
	router.POST("/user/manager", curd.Manager)                 //健康管理师
	router.POST("/user/perfect", curd.Perfect)                 //完善个人信息 ok
	router.POST("/user/pulse", curd.Pulse)                     //最近一次数字脉诊 pk
	router.POST("/user/pulse_add", curd.PulseAdd)              //数字脉诊上传 ok
	router.POST("/user/user_info", curd.UserInfo)              //查询用户个人信息
	router.POST("/user/user_pulse", curd.UserPulse2)           //检测4项结果查询
	router.POST("/user/user_pulse2", curd.UserPulse)           //检测4项结果查询
	router.POST("/user/user_interpret", curd.UserInterpret)    //用户解读方案合集
	router.POST("/user/user_pulse_list", curd.UserPulseLIst)   //检测记录  appoint=查询用户  *appoint*
	router.POST("/user/user_address_add", curd.UserAddressAdd) //收货地址添加
	router.POST("/user/user_address_up", curd.UserAddressUp)   //收货地址添加
	router.POST("/user/user_address", curd.UserAddress)        //收货地址查询
	router.POST("/user/lock", curd.Lock)                       //解锁查询记录
	router.POST("/user/vip", curd.Vip)                         //超级会员检查
	//router.POST("/user/renew", curd.Renew)                       //续费 创建订单
	router.POST("/user/t_code_list", curd.CodeList)            //激活码列表
	router.POST("/user/checkcode", curd.CheckCode)             //核销码的核销
	router.POST("/user/user_extract_add", curd.UserExtractAdd) //提现添加
	router.POST("/user/user_extract", curd.UserExtract)        //提现列表

	//todo 发现、商城、大数据
	router.POST("/ddj/zs", curd.Zhishu)         //指数报告列表  appoint=查询用户  *appoint*
	router.POST("/ddj/pj", curd.Puji)           //指数报告列表  appoint=查询用户  *appoint*
	router.POST("/ddj/zs_info", curd.Zhishumes) //指数报告列表详情
	router.POST("/ddj/pj_info", curd.Pujimes)   //指数报告列表详情

	//获取微信分享二维码
	router.POST("/user/qrcode", curd.Qrcode)

	//日常健康

	router.POST("/day/add", curd.DayAdd)           // 日常健康录入
	router.POST("/day/list", curd.DayList)         // 日常健康录入  appoint=查询用户  *appoint*
	router.POST("/day/info", curd.DayInfo)         // 日常健康录入
	router.POST("/check/add", curd.CheckAdd)       // 日常健康录入
	router.POST("/check/list", curd.CheckList)     // 日常健康录入  appoint=查询用户  *appoint*
	router.POST("/check/info", curd.CheckInfo)     // 日常健康录入
	router.POST("/special/add", curd.SpecialkAdd)  // 日常健康录入
	router.POST("/special/list", curd.SpecialList) // 日常健康录入  appoint=查询用户  *appoint*
	router.POST("/special/info", curd.SpecialInfo) // 日常健康录入
	//2022年3月13日
	//家庭空间 绑定 查看记录 1 配偶 2父亲 3母亲 4 配偶父亲 5配偶母亲 6子女1 7 子女2   8其他
	router.POST("/space/bind", curd.SpaceBind)

	//体质辨识 增 查
	router.POST("/analysis/add", curd.Anadd)
	router.POST("/analysis/list", curd.AnaList) //诊断列表
	router.POST("/analysis/info", curd.AnaInfo) //诊断详情
	//每月赠送

	//微信小程序预支付下单
	router.POST("/get_pay_info", curd.GetPayInfo)
	router.POST("/user/bonus_list", curd.BonusList) //分佣明细列表
	//直推人员列表
	router.POST("/user/recommend_list", curd.RecommendList) //直推人员列表
}

type Info struct {
	PrepayId string `json:"prepay_id"`
	PaySign  string `json:"pay_sign"`
}

/*
	获取支付签名
*/

func (demo *ApiController) GetPayInfo(c *gin.Context) {
	var (
		mchID                      string = "1617872033"                               // 商户号
		mchCertificateSerialNumber string = "739FD66ADDAD2F525FD15F7385451058AA0F9946" // 商户证书序列号
		mchAPIv3Key                string = "3064fe4604d1d08b5490b6ff093ce022"         // 商户APIv3密钥
	)

	// 使用 utils 提供的函数从本地文件中加载商户私钥，商户私钥会用来生成请求的签名
	mchPrivateKey, err := utils.LoadPrivateKeyWithPath("pem_path/apiclient_key.pem")
	if err != nil {
		log.Fatal("load merchant private key error")
	}

	ctx := context.Background()
	// 使用商户私钥等初始化 client，并使它具有自动定时获取微信支付平台证书的能力
	opts := []core.ClientOption{
		option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
	}
	client, err := core.NewClient(ctx, opts...)
	if err != nil {
		log.Fatalf("new wechat pay client err:%s", err)
	}

	//接收表单参数，并查询订单信息
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Payinfo{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, order := (&dao.Order{}).OrderInfo(c, tx, parms.OrderId)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	productid := order.ProductId
	log.Println(productid)
	totalNum := order.TotalNum
	pro_name := ""
	if productid > 0 {
		//查询产品
		err, product := (&dao.Product{}).FindProduct2(c, tx, strconv.Itoa(productid))
		if err != nil {
			middleware.ResponseError(c, 100, err)
			return
		}
		if productid == 12 {
			pro_name = "会员充值" + strconv.Itoa(int(totalNum)) + "个月"
		} else {
			//判断product.StoreName的长度
			if len(product.StoreName) > 20 {
				pro_name = product.StoreName[1:21]
			} else {
				pro_name = product.StoreName
			}
		}
	} else {
		pro_name = "会员充值一年"
	}

	//查询用户openid
	token := c.Request.Header.Get("token") //从headers获取token
	claims, err := jwt.ParseToken(token)
	uid := claims.Uid
	err, user := (&dao.Uuser{}).FindUser(c, tx, uid)
	if err != nil {
		middleware.ResponseError(c, 100, err)
	}
	openid := user.Openid
	log.Println(openid)
	//jiage
	total_price := order.TotalPrice
	//dealint_price := total_price.IntPart()
	//dealint_price *= 100
	number := 100
	//100转化成decimal
	number_decimal := decimal.NewFromFloat(float64(number))
	//decimal乘法,最终价格dealint_price
	result_price := total_price.Mul(number_decimal)
	dealint_price := result_price.IntPart()
	//pro_info := product.StoreInfo
	// 发送请求，以下载微信支付平台证书为例
	// https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay5_1.shtml
	//svc := certificates.CertificatesApiService{Client: client}
	//resp, result, err := svc.DownloadCertificates(ctx)
	//log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	svc := jsapi.JsapiApiService{Client: client}
	//查询订单

	// 得到prepay_id，以及调起支付所需的参数和签名
	resp, _, err := svc.PrepayWithRequestPayment(ctx,
		jsapi.PrepayRequest{
			Appid:       core.String("wx2986f0dea031f5a8"),
			Mchid:       core.String("1617872033"),
			Description: core.String(pro_name),

			OutTradeNo: core.String(parms.OrderId),
			Attach:     core.String(""),
			NotifyUrl:  core.String("https://haili.yidenetwork.com/order/notify_url"),
			Amount: &jsapi.Amount{
				Total: core.Int64(dealint_price), //
			},
			Payer: &jsapi.Payer{
				Openid: core.String(openid),
			},
		},
	)
	type ResJsonPay struct {
		Appid     string `json:"appid"`
		Partnerid string `json:"partnerid"`
		Prepayid  string `json:"prepayid"`
		Package   string `json:"package"`
		Noncestr  string `json:"noncestr"`
		Timestamp string `json:"timestamp"`
		Sign      string `json:"sign"`
		PayType   string `json:"payType"`
	}
	if err == nil {
		//log.Println(resp)
		resJson := ResJsonPay{
			Appid:     *resp.Appid,
			Partnerid: "1617872033",
			Prepayid:  *resp.PrepayId,
			Package:   *resp.Package,
			Noncestr:  *resp.NonceStr,
			Timestamp: *resp.TimeStamp,
			Sign:      *resp.PaySign,
			PayType:   "RSA",
		}
		//jsonBytes, _ := json.Marshal(resJson)
		//fmt.Println(string(jsonBytes))
		middleware.ResponseSuccess(c, resJson)
	} else {
		log.Println(err)
		middleware.ResponseError(c, 408, err)
	}

}

//Login 无需授权手机的授权登录
/*
	return token 1 year
	return uid
*/

func (demo *ApiController) Scheme(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Dl{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Uuser{}).Scheme(c, tx, parms.Did)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}
func (demo *ApiController) SpaceBind(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Space{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Uspace{}).SpaceBind(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 分佣列表
func (demo *ApiController) BonusList(c *gin.Context) {
	fmt.Println("分佣列表列表")
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, data := (&dao.Bonu{}).SelectBonus(c, tx)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//fmt.Println(data)
	middleware.ResponseSuccess(c, &data)

}

//直推人员列表
func (demo *ApiController) RecommendList(c *gin.Context) {
	fmt.Println("直推人员列表")
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Tuser{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//parms.Uid转int
	fmt.Println(parms)
	err, data := (&dao.Uuser{}).TuiList(c, tx, parms.Uid)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, &data)

}

// 激活码的列表
func (demo *ApiController) CodeList(c *gin.Context) {
	fmt.Println("激活码列表")
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.CkCodeList{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, data := (&dao.Wcode2{}).CodeList(c, tx, parms.Uid, parms.Status)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//fmt.Println(data)
	middleware.ResponseSuccess(c, &data)

}

// 核销码的核销
func (demo *ApiController) CheckCode(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.CkCode{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, data := (&dao.Wcode{}).CheckCode(c, tx, parms)
	if err != nil {
		middleware.ResponseError2(c, 100, &data)
		return
	}
	//fmt.Println(data)
	middleware.ResponseSuccess(c, &data)

}

func (demo *ApiController) Anadd(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Ana{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Analysis{}).Anadd(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

func (demo *ApiController) AnaList(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Appoint{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Analysis{}).AnaList(c, tx, parms.AppoId, parms.Type)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}
func (demo *ApiController) AnaInfo(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addinfo{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Analysis2{}).Anainfo(c, tx, parms.Id)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}
func (demo *ApiController) CheckAdd(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addday{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Check{}).Checkhe(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 日常健康录入
func (demo *ApiController) CheckList(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addlist{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Check{}).Checklist(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 日常健康录入
func (demo *ApiController) SpecialInfo(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addinfo{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Check{}).Specialinfo(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}
func (demo *ApiController) SpecialkAdd(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addday{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Check{}).Specialhe(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 日常健康录入
func (demo *ApiController) SpecialList(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addlist{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Check{}).Speciallist(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 日常健康录入
func (demo *ApiController) CheckInfo(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addinfo{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Check{}).Checkinfo(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 日常健康录入
func (demo *ApiController) DayAdd(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addday{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Self{}).Addhe(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 日常健康录入
func (demo *ApiController) DayList(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addlist{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Self{}).Addlist(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 日常健康录入
func (demo *ApiController) DayInfo(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Addinfo{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, b := (&dao.Self{}).Addinfo(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 超级会员检查
func (demo *ApiController) Vip(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Uid{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	b, err := (&dao.Vip{}).CheckVip(c, tx, parms.Uid)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 获取会员分享二维码
func (demo *ApiController) Qrcode(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Uid{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Uuser{}).GetWXcode(c, tx, parms.Uid)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 获取代理分享二维码
func (demo *ApiController) Dlqrcode(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Dl{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, b := (&dao.Uuser{}).DlWXcode(c, tx, parms.Did)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 获取代理分享二维码2
func (demo *ApiController) qrcode2(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	parms := &dto.Dl2{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	log.Println(parms.Did)
	err, b := (&dao.Uuser{}).DlWXcode2(c, tx, parms.Did)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, b)
}

// 指数
func (demo *ApiController) Zhishu(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Appoint{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, list := (&dao.Cid{}).ZHIshulist(c, tx, parms.AppoId)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, list)
}

// 普及自助版
func (demo *ApiController) Puji(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Appoint{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, list := (&dao.Cid{}).Pjlist(c, tx, parms.AppoId)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, list)
}

// 指数详情
func (demo *ApiController) Zhishumes(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Ddj{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, list := (&dao.Zhishu{}).ZHIshumes(c, tx, parms.Id)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, list)
}

// 普及自助版详情
func (demo *ApiController) Pujimes(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Ddj{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, list := (&dao.Zz{}).Pjmes(c, tx, parms.Id)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, list)
}

//这是一个公共的上传类oss的 文件名称 imgfile
var commonPath = "/www/wwwroot/haili/imgss"

func (demo *ApiController) UploadFile(c *gin.Context) {
	file, err := c.FormFile("cover")
	if err != nil {
		fmt.Println("get picture:", err)
		return
	}
	dst := path.Join(commonPath, file.Filename)
	err = c.SaveUploadedFile(file, dst)
	if err != nil {
		fmt.Println("upload error:", err)
		return
	}
	fmt.Println("upload success!")
	//
	//endpoint := "http://oss-cn-beijing.aliyuncs.com"
	//accessKeyId := "LTAI5tGQntrEsXrVD4ZKH6rF"
	//accessKeySecret := "kwnU0K1xyp0YZism6eilflHIxLadb7"
	//bucketName := "jiankangdanganguan2"
	//// 创建OSSClient实例。
	//client, err := oss.New(endpoint, accessKeyId, accessKeySecret)
	//if err != nil {
	//	log.Println(err)
	//}
	//// 创建存储空间。
	//err = client.CreateBucket(bucketName)
	//if err != nil {
	//	log.Println(err)
	//}

}
func (demo *ApiController) Tongbu(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 2001, err)
		return
	}
	go func() {
		errx := (&dao.Admin2{}).Puji(tx)
		errx = (&dao.Admin2{}).FindUUU(tx)
		fmt.Println(errx)
	}()

}
func (demo *ApiController) Login(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	api := &dto.LoginInput{}
	if err := api.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//获取微信配置  可以写成公共函数
	viper.SetConfigName("base")
	viper.SetConfigType("toml")
	viper.AddConfigPath("./conf/dev/")
	err = viper.ReadInConfig()
	if err != nil {
		var errs = errors.New("获取配置错误")
		middleware.ResponseError(c, 100, errs)
		return
	}
	appId := viper.Get("wxConfig.appId")
	appSecret := viper.Get("wxConfig.appsecret")
	url := "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code"
	log.Println("登录--------------")
	resp, err := http.Get(fmt.Sprintf(url, appId, appSecret, api.Code))
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		middleware.ResponseError(c, 100, errors.New("resp error"))
		return
	}
	var obj RespWXSmall
	log.Println("body--------------")
	log.Println(string(body))
	err = json.Unmarshal(body, &obj)
	if err != nil {
		return
	}
	//fmt.Println(obj)
	if obj.Errcode != 0 {
		middleware.ResponseError(c, 100, errors.New(obj.ErrMsg))
		return
	}
	//存储数据库或者获取Uid

	token, uid := (&dao.Uuser{}).Find(c, tx, obj.Openid, api.Hid, api.Fid)
	obj.Token = token
	obj.Uid = uid
	user := &dao.Uuser{}
	tx.Table("hr_wx_user").Where("id = ?", uid).First(&user)
	obj.Headimgurl = user.Headimgurl
	middleware.ResponseSuccess(c, obj)
}

// Lock 解锁
func (demo *ApiController) Lock(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.PulseLock{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(parms)
	_, err = (&dao.Pulse{}).Lock(c, tx, parms.Id, parms.Uid, parms.Type)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, "success")
}

// UserAddressADD 收货地址添加
func (demo *ApiController) UserAddressAdd(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Address{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, data := (&dao.Address{}).AddressAdd(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, data)
}

// UserExtractADD 用户提现添加
func (demo *ApiController) UserExtractAdd(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.UserExtract{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, data := (&dao.UserExtract{}).UserExtractAdd(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, data)
}

// UserAddressADD 收货地址修改
func (demo *ApiController) UserAddressUp(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Address{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, data := (&dao.Address{}).AddressUp(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, data)
}

// Notice 公告
func (demo *ApiController) Notice(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	data, err := (&dao.Notice{}).FindNotice(c, tx)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, data)
}

// UserExtract 用户提现记录
func (demo *ApiController) UserExtract(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, data := (&dao.UserExtract{}).UserExtract(c, tx)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, data)
}

// UserAddressADD 收货地址
func (demo *ApiController) UserAddress(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, data := (&dao.Address{}).Address(c, tx)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, data)
}

// UserPulseLIst 查询指定会员的检测记录.可以绑定家庭空间查询
func (demo *ApiController) UserPulseLIst(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Appoint2{}
	log.Println(parms)
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, data := (&dao.Pulse{}).UserSelect(c, tx, parms.AppoId)
	if err != nil {
		middleware.ResponseError(c, 100, err)
	}
	middleware.ResponseSuccess(c, data)
}

// UserInfo 查询个人信息
func (demo *ApiController) UserInfo(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//parms := &dto.Uid{}
	//if err := parms.BindingValidParams(c); err != nil {
	//	middleware.ResponseError(c, 100, err)
	//	return
	//}
	token := c.Request.Header.Get("token") //从headers获取token
	claims, err0 := jwt.ParseToken(token)
	if err0 != nil {
		return
	}
	err, data := (&dao.Uuser{}).FindUser(c, tx, claims.Uid)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, data)
}

//UserPulse 检查结果查询
func (demo *ApiController) UserPulse(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Pulse{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, data := (&dao.PulseInfo{}).PulseInfo(c, tx, parms.Id)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//fmt.Println(data)
	middleware.ResponseSuccess(c, &data)
}

//UserPulse2 检查结果查询
func (demo *ApiController) UserPulse2(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.Pulse{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	err, data := (&dao.PulseInfoA{}).PulseInfoA(c, tx, parms.Id)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//fmt.Println(data)
	middleware.ResponseSuccess(c, &data)
}

//UserPulse3 解读方案合集
func (demo *ApiController) UserInterpret(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//parms := &dto.PulseXin{}
	//if err := parms.BindingValidParams(c); err != nil {
	//	middleware.ResponseError(c, 100, err)
	//	return
	//}

	err, data := (&dao.PulseInfoB{}).PulseInfoB(c, tx) //, parms.Uid
	//判断&PulseInfoB是否为空的结构体
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(data)
	//判断data中data.Interpret是否存在
	if len(data.Interpret) == 0 {
		middleware.ResponseSuccess(c, "暂无数据")
	} else {
		middleware.ResponseSuccess(c, &data)
	}

}

// Perfect 完善信息
func (demo *ApiController) Perfect(c *gin.Context) {
	fmt.Println(111)
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	parms := &dto.UserInfo{}
	if err := parms.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	token := c.Request.Header.Get("token") //从headers获取token
	claims, err0 := jwt.ParseToken(token)
	if err0 != nil {
		return
	}
	parms.Uid = claims.Uid
	err, data := (&dao.Uuser{}).Perset(c, tx, parms)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//fmt.Println(data)
	middleware.ResponseSuccess(c, &data)

}

// Test Token 测试
func (demo *ApiController) Test(c *gin.Context) {
	fmt.Println("token通过")
	return
}

// News 健康贴士
func (demo *ApiController) News(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	result, err := (&dao.NewsGetFour{}).Article(c, tx)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, result)
}

//通过id 查找制定文章
func (demo *ApiController) NewsID(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	params := &dto.Article{}

	if err := params.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	result, err := (&dao.EveryList{}).Articleone(c, tx, params.Id)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, result)
}
func (demo *ApiController) MoveNewsList(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	result, err := (&dao.EveryList{}).FindNewsList2(c, tx)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, result)
}
func (demo *ApiController) NewsList(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	result, err := (&dao.EveryList{}).FindNewsList(c, tx)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, result)
}

//Manager 健康管理师
func (demo *ApiController) Manager(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	params := &dto.Uid{}

	if err := params.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(params.Uid)
	result, err := (&dao.Admin{}).AdminUser(c, tx, params.Uid)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	middleware.ResponseSuccess(c, result)
}

//Pulse 数据脉诊
func (demo *ApiController) Pulse(c *gin.Context) {

	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	params := &dto.PulseXin{}

	if err := params.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//查询最近一次数字脉诊
	err, data := (&dao.PulseInfo{}).PulseInfoLast(c, tx, params.Uid)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}

	middleware.ResponseSuccess(c, data)
}

//PulseAdd 数据脉诊提交
func (demo *ApiController) PulseAdd(c *gin.Context) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	params := &dto.PulseAdd{}

	if err := params.BindingValidParams(c); err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	err, user := (&dao.Uuser{}).FindUser(c, tx, params.Uid)
	if len(user.Truename) <= 0 {
		middleware.ResponseError(c, 100, errors.New("请先完善个人信息"))
		return
	}
	//新增会员你有效期判断 todo
	err, addId := (&dao.Pulse{}).UserPulse(c, tx, params.Uid, params.Leftrate, params.Leftlowpre, params.Lefthightpre, params.Rightrate, params.Rightlowpre, params.Righthightpre)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	//五脏
	err, wid := (&dao.UserWuzhang{}).UserWuzhang(c, tx, addId, params.Uid, params.Leftrate, params.Leftlowpre, params.Lefthightpre, params.Rightrate, params.Rightlowpre, params.Righthightpre)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(wid)
	//六腑
	err, lid := (&dao.UserLiufu{}).UserLiufu(c, tx, addId, params.Uid, params.Leftrate, params.Leftlowpre, params.Lefthightpre, params.Rightrate, params.Rightlowpre, params.Righthightpre)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(lid)
	//体质
	err, tizhi := (&dao.Tizhi{}).Tizhi(c, tx, addId, params.Uid, params.Leftrate, params.Leftlowpre, params.Lefthightpre, params.Rightrate, params.Rightlowpre, params.Righthightpre)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(tizhi)
	//重疾病
	err, dabing := (&dao.Dabing{}).Dabing(c, tx, addId, params.Uid, params.Leftrate, params.Leftlowpre, params.Lefthightpre, params.Rightrate, params.Rightlowpre, params.Righthightpre)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(dabing)
	//加个状态走异步更新一下
	err, rid := (&dao.Pulse{}).UserUpdate(c, tx, addId)
	if err != nil {
		middleware.ResponseError(c, 100, err)
		return
	}
	fmt.Println(rid)
	//走异步生成pdf 上传oss
	go func() {
		(&dao.PulseInfo{}).Pdf(c, tx, addId, params.Uid)
		(&dao.PulseInfo{}).Pdfliufu(c, tx, addId, params.Uid)
		(&dao.PulseInfo{}).Pdftz(c, tx, addId, params.Uid)
		(&dao.PulseInfo{}).Dbfliufu(c, tx, addId, params.Uid)
	}()
	middleware.ResponseSuccess(c, addId)

}

// TestTable 异步文件处理服务
func (demo *ApiController) TestTable(c *gin.Context) {

	//tx, err := lib.GetGormPool("default")
	//if err != nil {
	//	middleware.ResponseError(c, 100, err)
	//	return
	//}
	//(&dao.PulseInfo{}).Pdf(c, tx, 1, 3)
	err := GeneratePdf("hello5.pdf")
	if err != nil {
		log.Print(err)
	}
	//上传oss
	client, err := oss.New("oss-cn-beijing.aliyuncs.com", "LTAI5tBAYs2KFZNdG421dyG4", "yctYH4qiVIhnJUDiNFP38msxnkQrwO")
	if err != nil {
		// HandleError(err)
	}

	bucket, err := client.Bucket("jiankangdanganguan")
	fmt.Println(bucket)
	if err != nil {
		// HandleError(err)
	}

	err = bucket.PutObjectFromFile("hello5.pdf", "./hello5.pdf")
	if err != nil {
		// HandleError(err)
	}
	//删除本地生成的Pdf
	//err = os.Remove("hello5.pdf")
	//if err != nil {
	//
	//} else {
	//	// 删除成功
	//}
}

func GeneratePdf(filename string) error {

	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{PageSize: *gopdf.PageSize10x14})
	pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeMysqlSelf})
	pdf.AddPage()
	//设置font
	err := pdf.AddTTFFont("wst11", "./font/NotoSansSC-Regular.ttf")
	if err != nil {
		log.Print(err.Error())
		return nil
	}
	err = pdf.SetFont("wst11", "", 11)
	if err != nil {
		log.Print(err.Error())
		return nil
	}

	//添加表格的标题
	pdf.SetX(47)
	pdf.SetY(45)

	alignOption := gopdf.CellOption{Align: gopdf.Middle | 0,
		Border: 0 | 0 | 0 | 0}
	alignOption2 := gopdf.CellOption{Align: gopdf.Middle | 0,
		Border: 0 | 0 | 0 | 0}
	pdf.CellWithOption(&gopdf.Rect{
		W: 100,
		H: 83,
	}, "", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 300,
		H: 83,
	}, "邹平泰润食品贸易有限公司", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 170,
		H: 83,
	}, "", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 83,
	}, "2020", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 20,
		H: 83,
	}, "07", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 20,
		H: 83,
	}, "01", alignOption2)

	pdf.SetX(47)
	pdf.SetY(70)
	pdf.CellWithOption(&gopdf.Rect{
		W: 100,
		H: 133,
	}, "", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 300,
		H: 133,
	}, "粉皮", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 160,
		H: 133,
	}, "", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "斤", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "120.00", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "6.00", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "720.00", alignOption2)

	pdf.SetX(47)
	pdf.SetY(90)
	pdf.CellWithOption(&gopdf.Rect{
		W: 100,
		H: 133,
	}, "", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 300,
		H: 133,
	}, "粉条", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 160,
		H: 133,
	}, "", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "斤", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "120.00", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "6.00", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "720.00", alignOption2)

	pdf.SetX(47)
	pdf.SetY(110)
	pdf.CellWithOption(&gopdf.Rect{
		W: 100,
		H: 133,
	}, "", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 300,
		H: 133,
	}, "咸菜丝", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 160,
		H: 133,
	}, "", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "斤", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "40.00", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "1.60", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "64.00", alignOption2)

	pdf.SetX(47)
	pdf.SetY(130)
	pdf.CellWithOption(&gopdf.Rect{
		W: 100,
		H: 133,
	}, "", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 300,
		H: 133,
	}, "花生米", alignOption)
	pdf.CellWithOption(&gopdf.Rect{
		W: 160,
		H: 133,
	}, "", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "斤", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "100.00", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "7.50", alignOption2)
	pdf.CellWithOption(&gopdf.Rect{
		W: 40,
		H: 133,
	}, "750.00", alignOption2)
	err = pdf.WritePdf(filename)
	if err != nil {
		fmt.Println(err)
	}
	return nil

}
